#include "stdafx.h"
#include "ShaderContainer.h"
#include "GraphicsManager.h"

ShaderContainer::ShaderContainer(void)
{

}

ShaderContainer::ShaderContainer(ID3D11VertexShader* vertexShader, ID3D11PixelShader* pixelShader)
{
	this->vertexShader = vertexShader;
	this->pixelShader = pixelShader;
}

ShaderContainer::~ShaderContainer(void)
{
	if (vertexShader)
		vertexShader->Release();
	if (pixelShader)
		pixelShader->Release();
	if (geometryShader)
		geometryShader->Release();
}

void ShaderContainer::MakeVertexShader(BYTE* shaderCode, unsigned int codeSize)
{
	vertexShader = GraphicsManager::GetInstance()->createVertexShader(shaderCode, codeSize);
}

void ShaderContainer::MakePixelShader(BYTE* shaderCode, unsigned int codeSize)
{
	pixelShader = GraphicsManager::GetInstance()->createPixelShader(shaderCode, codeSize);
}

void ShaderContainer::MakeGeometryShader(BYTE* shaderCode, unsigned int codeSize)
{
	geometryShader = GraphicsManager::GetInstance()->createGeometryShader(shaderCode, codeSize);
}

void ShaderContainer::Bind(void)
{
	// store a pointer to graphics manager
	GraphicsManager* graphics = GraphicsManager::GetInstance();

	// send each shader to the pipeline
	graphics->getDeviceContext()->VSSetShader(vertexShader, nullptr, 0);
	graphics->getDeviceContext()->PSSetShader(pixelShader, nullptr, 0);
	graphics->getDeviceContext()->GSSetShader(geometryShader, nullptr, 0);
}